﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using BUS;

namespace GUI
{
    public partial class login : UserControl
    {
        public login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string tendangnhap = txtTenDangNhap.Text.Trim();
            string matkhau = txtMatKhau.Text.Trim();
            try
            {
                NguoiDung log = new NguoiDungBUS().Login(tendangnhap, matkhau);
                @LogedIn.login = log;
                unLoginPanel.Visible = false;
                loggedInPanel.Visible = true;
                loggedInPanel.Location = new Point(3, 3);
                lblUser.Text = log.HoVaTen;
                if (log.PhanQuyen.Equals("Administrator")) {
                    ctrAdmin1.Visible = true;
                    ctrMod1.Visible = true;
                    ctrNguoiDung1.Visible = true;
                }
                else if (log.PhanQuyen.Equals("Moderator"))
                {
                    ctrMod1.Visible = true;
                    ctrNguoiDung1.Visible = true;
                }
                else
                {
                    ctrNguoiDung1.Visible = true;
                }
            }
            catch
            {
                lblMess.Text = "Sai thông tin đăng nhập";
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            @LogedIn.login = null;
            unLoginPanel.Visible = true;
            loggedInPanel.Visible = false;

            ctrAdmin1.Visible = false;
            ctrMod1.Visible = false;
            ctrNguoiDung1.Visible = false;

            lblMess.Text = null;
        }
    }
}
